/* eslint-disable no-undef */
/**
 * Created by msi on 2017/12/19 0019.
 */

var d3 = require("d3")
var ChordDiagram = function () {
    var my = {}
    //数据格式为

    //[['Arsenal','Aston Villa',6]]


    function drawChordDiagram(allFlows) {
        if (document.getElementById("chordDiagram"))
            document.getElementById("chordDiagram").innerHTML = "";
        var data = allFlows.map((flow) => {
            var temData = [];
            temData.push(flow.getStartPt().name)
            temData.push(flow.getEndPt().name)
            temData.push(flow.getValue())
            return temData;
        })

        var color = d3.scale.category20().domain(d3.range(20));

        var a = d3.rgb(255, 0, 0);    //红色
        var b = d3.rgb(0, 255, 0);    //绿色

        var compute = d3.interpolate(a, b);

        var linear = d3.scale.linear()
            .domain([0, 1000])
            .range([0, 1]);

        var svg = d3.select("#chordDiagram").append("svg").attr("height", "500px").attr("width", "100%");
        var ch = viz.ch().data(data)
            .padding(.01)
            .innerRadius(110)
            .outerRadius(80)
            .duration(1000)
            .chordOpacity(0.3)
            .labelPadding(.5)
            .fill(function (text) {
                // console.log(value)
                // return compute(linear(value))
                return color(text);
            });
        svg.append("g").attr("transform", "translate(180,150)").call(ch);
        svg.selectAll("text").attr("fill", "blue").attr("font-size", "5px");
    }


    my.drawChordDiagram = function (allFlows) {
        drawChordDiagram(allFlows);
    };

    return my
};
export default ChordDiagram;